
using System;
using System.Collections.Generic;
using BTKERP.Model;
using BTKERP.DAL.DataAccess;
using System;

namespace BTKERP.DAL
{
	#region RequisitionDetailDAL
	public class RequisitionDetailDAL : DBContext
	{
		public List<RequisitionDetail> GetAll()
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_RequisitionDetailsSelectAll");
            return GetEntityList<RequisitionDetail>(cmd);
        }

        public List<RequisitionDetail> GetByMasterId(Guid id)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_RequisitionDetailSelectByMasterId");
            cmd.AddParameter("@ResuisitionId", id);
            return GetEntityList<RequisitionDetail>(cmd);
        }

		public List<RequisitionDetail> GetByDynamicSQL(string sqlCondition)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_RequisitionDetailSelectDynamic");
            cmd.AddParameter("@SQL", sqlCondition);
            return GetEntityList<RequisitionDetail>(cmd);
        } 
		
        public bool DeleteById(Guid id,Guid productId)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_RequisitionDetailDelete");
            cmd.AddParameter("@requisitionId", id);
            cmd.AddParameter("@productId", productId);
            return ExecuteCommand(cmd);
        }

        public RequisitionDetail UpdateById(Guid paramResuisitionId, Guid paramProductId, Guid paramUnitId,	decimal paramUnitPrice,
                                            decimal paramRequestedQty, decimal paramRequstedTotal, decimal paramApprovedQty, decimal paramApprovedTotal,
                                            decimal paramDeliveredQty, string paramStatus, string paramUpdatedBy)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_RequisitionDetailUpdate");
			cmd.AddParameter("@ResuisitionId", paramResuisitionId);
			cmd.AddParameter("@ProductId", paramProductId);
			cmd.AddParameter("@UnitId", paramUnitId);
			cmd.AddParameter("@UnitPrice", paramUnitPrice);
			cmd.AddParameter("@RequestedQty", paramRequestedQty);
			cmd.AddParameter("@RequstedTotal", paramRequstedTotal);
			cmd.AddParameter("@ApprovedQty", paramApprovedQty);
			cmd.AddParameter("@ApprovedTotal", paramApprovedTotal);
			cmd.AddParameter("@DeliveredQty", paramDeliveredQty);
			cmd.AddParameter("@Status", paramStatus);
			cmd.AddParameter("@UpdatedBy", paramUpdatedBy);
            return GetSingleEntity<RequisitionDetail>(cmd);
        }


        public void  UpdateProcess(System.Guid resuisitionId, System.Guid productId, System.Guid unitId, int requestQty, string updateBy)
        {
            ExSQLCommand cmd = new ExSQLCommand("RequisitionDetailUpdateProcess");
            cmd.AddParameter("@ResuisitionId", resuisitionId);
            cmd.AddParameter("@ProductId", productId);
            cmd.AddParameter("@UnitId", unitId);
            cmd.AddParameter("@RequestedQty", requestQty);
            cmd.AddParameter("@UpdatedBy", updateBy);
            ExecuteCommand(cmd);
        }
    }
	#endregion
}
